<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;

class ComboTreeController extends CommonController {
    
    /**
     * 北京[1000]  上海[5000]  天津[1500] 直接可选
     * @date: 2017年8月5日 上午11:07:49
     */
    public function city(){
        
        $pass = array('1000','1500','5000','11500');
        $cascadedata = M('cascadedata');
        $map = array();
        $map['datagroup'] = 'schoolArea';
        $map['level'] = '0';
        $rows = $cascadedata->where($map)->select();
        $result = array();
        foreach($rows as $row){
            $single = array();
            $single['id'] = $row['datavalue'];
            $single['text'] = $row['dataname'];
            $single['datavalue'] = $row['datavalue'];
            if(in_array($row['datavalue'], $pass)){
                
            }else{
                $single['state'] = "closed";
                $map = array();
                $map['datagroup'] = 'schoolArea';
                $map['level'] = '1';
                //datavalue必须转换为整形不然查询会出错
                $map['datavalue'] = array(array('gt',(int)($row['datavalue'])),array('lt',$row['datavalue']+500));
                $rows2 = $cascadedata->where($map)->select();
                $single['children'] = array();
                foreach($rows2 as $row2){
                    $single2 = array();
                    $single2['id'] = $row2['datavalue'];
                    $single2['text'] = $row2['dataname'];
                    array_push($single['children'], $single2);
                }
                
            }
            
            array_push($result, $single);
        }
        //print_r($result);
        $this->ajaxReturn($result);
        
    }
    
    
}